<template>
  <div>
    <h1>新增用户</h1>
    用户名：<input type="text" v-model.trim="user.name" /><br />
    年龄:<input type="number" v-model.trim.number="user.age" /><br />
    <button @click="submit">提交</button>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

import { createUserApi } from '@/api/users.js'

const user = ref({ name: '', age: '' })
const router = useRouter()

const submit = async () => {
  await createUserApi(user.value)
  alert('用户添加成功')
  router.push('/')
}
</script>

<style scoped></style>
